﻿using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ProjectEuler.Core.Helpers;

namespace ProjectEuler.Core
{
    public class Problem3 : IProjectEulerProblem
    {
        //The prime factors of 13195 are 5, 7, 13 and 29.

        public int Number
        {
            get { return 3; }
        }

        public string Description
        {
            get { return "Find the largest prime factor of the number 600851475143"; }
        }

        public string Answer
        {
            get { return MathHelper.PrimeFactorsOf(600851475143).Max().ToString(); }
        }
    }

    [TestFixture]
    public class When_getting_PrimeFactors
    {
        [Test]
        public void Then_prime_factors_of_8_should_be_2_2_2()
        {
            var primefactorsof8 = MathHelper.PrimeFactorsOf(8);
            Assert.AreEqual(2,primefactorsof8[0]);
            Assert.AreEqual(2, primefactorsof8[1]);
            Assert.AreEqual(2, primefactorsof8[2]);
        }

        [Test]
        public void Then_prime_factors_of_20_should_be_2_2_5()
        {
            var primefactorsof20 = MathHelper.PrimeFactorsOf(20);
            Assert.AreEqual(2, primefactorsof20[0]);
            Assert.AreEqual(2, primefactorsof20[1]);
            Assert.AreEqual(5, primefactorsof20[2]);
        }
    }
}

